package handle

import "math"

const abortIndex int8 = math.MaxInt8 >> 1

type ELContext struct {
	handleIndex int
	handles     []elHandle
}
type elHandle = func(ctx *ELContext)

func (e *ELContext) Use(handles ...elHandle) {
	e.handles = append(e.handles, handles...)
}

func (e *ELContext) Get(path string, handles ...elHandle) {
	e.handles = append(e.handles, handles...)
}
func (e *ELContext) Next() {
	e.handleIndex++
	for e.handleIndex < len(e.handles) {
		e.handles[e.handleIndex](e)
		e.handleIndex++
	}
	//if len(e.handles) <= e.handleIndex+1 {
	//	return
	//}
	//e.handleIndex++
	//
	//e.handles[e.handleIndex](e)

}
func (e *ELContext) Abort() {
	e.handleIndex = int(abortIndex)

}
func (e *ELContext) Run() {
	if len(e.handles) > 0 {
		e.handles[0](e)
	}
}
